"""
    Additional info on this here: http://code.google.com/appengine/articles/remote_api.html
    
    From the remote_shell: (Here's how to delete all the RawFeed entities for owner = 420070377
    
     from entity_deleter import BulkDeleter
     from models import *
     from google.appengine.ext import deferred
      
    filters = []
    filter = ('owner', '420070377')
    filters.append(filter)
    mapper = BulkDeleter(RawFeed, filters=filters)
    deferred.defer(mapper.run)

"""

from mapper import Mapper
from models import *

class BulkDeleter(Mapper):
    def __init__(self, kind, filters=None):
        Mapper.__init__(self)
        self.KIND = kind
        if filters:
          self.FILTERS = filters

    def map(self, entity):
        return ([], [entity])

class OldEntityDeleter(Mapper):
    def __init__(self, kind, threshold):
        Mapper.__init__(self)
        self.KIND = kind
        self.threshold = threshold

    def get_query(self):
        q = self.KIND.all()
        q.filter("updated <=", self.threshold)
        q.order("updated")
        q.order("__key__")
        return q
        
    def map(self, entity):
        return ([], [entity])
